﻿using BBCore.Application.Interface;
using Microsoft.AspNetCore.Components.Authorization;

namespace BBCore.Application.Service
{
    public class GetLoginUserNameService: IGetLoginUserNameService
    {
        
        public async Task<string> GetLoginUserNameAsync(AuthenticationStateProvider authStateProvider)
        {
            var authState = await authStateProvider.GetAuthenticationStateAsync();
            var user = authState.User;

            if (user.Identity is not null && user.Identity.IsAuthenticated)
            {
                return user.Identity.Name!;
            }
            else
            {
                return "";
            }
        }
    }
}
